package com.xoms.front.controller.springmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import com.xoms.front.controller.res.*;
import com.xoms.front.controller.res.bean.*;
import com.xoms.front.controller.springmvc.req.*;

/**
 * 影厅相关接口
 **/
@Controller
@RequestMapping(value = "/room", produces = "application/json")
public class SRoomController {
	@Autowired
	com.xoms.front.controller.RoomController roomController;

	/**
	 * 获取影厅类型维度列表
	 **/
	@RequestMapping("/v1/getDimensions")
	@ResponseBody
	public ListResult<RRoomDimensionBean> getDimensions(HttpServletRequest request, HttpServletResponse response) {

		return roomController.getDimensions(request, response);
	}

	/**
	 * 获取影厅类型维度详细列表
	 **/
	@RequestMapping("/v1/getDimensionDetails")
	@ResponseBody
	public ListResult<RRoomDimensionDetailBean> getDimensionDetails(@Validated GetRoomDimensionDetailsParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RRoomDimensionDetailBean> res = new ListResult<RRoomDimensionDetailBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return roomController.getDimensionDetails(param, request, response);
	}

	/**
	 * 获取影厅状态列表
	 **/
	@RequestMapping("/v1/getRoomStatusList")
	@ResponseBody
	public ListResult<RRoomStatusListBean> getRoomStatusList(@Validated GetRoomStatusListParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RRoomStatusListBean> res = new ListResult<RRoomStatusListBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return roomController.getRoomStatusList(param, request, response);
	}

	/**
	 * 获取影厅列表
	 **/
	@RequestMapping("/v1/getRoomList")
	@ResponseBody
	public ListResult<RRoomListBean> getRoomList(@Validated GetRoomListParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RRoomListBean> res = new ListResult<RRoomListBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return roomController.getRoomList(param, request, response);
	}

	/**
	 * 获取影厅详情
	 **/
	@RequestMapping("/v1/getRoomInfo")
	@ResponseBody
	public ObjectResult<RRoomInfoBean> getRoomInfo(@Validated GetByIdParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RRoomInfoBean> res = new ObjectResult<RRoomInfoBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return roomController.getRoomInfo(param, request, response);
	}

	/**
	 * 获取指定影厅预定列表
	 **/
	@RequestMapping("/v1/getRoomBookList")
	@ResponseBody
	public ListResult<RRoomBookInfoBean> getRoomBookList(@Validated GetByIdParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RRoomBookInfoBean> res = new ListResult<RRoomBookInfoBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return roomController.getRoomBookList(param, request, response);
	}

	/**
	 * 通过会员卡号获取会员信息
	 **/
	@RequestMapping("/v1/getUserInfoByCard")
	@ResponseBody
	public ObjectResult<RUserInfoBean> getUserInfoByCard(@Validated GetUserInfoByCardParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RUserInfoBean> res = new ObjectResult<RUserInfoBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return roomController.getUserInfoByCard(param, request, response);
	}

	/**
	 * 通过手机号获取会员信息
	 **/
	@RequestMapping("/v1/getUserInfoByTel")
	@ResponseBody
	public ObjectResult<RUserInfoBean> getUserInfoByTel(@Validated GetUserInfoByTelParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RUserInfoBean> res = new ObjectResult<RUserInfoBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return roomController.getUserInfoByTel(param, request, response);
	}

	/**
	 * 获取电影列表
	 **/
	@RequestMapping("/v1/getFilmList")
	@ResponseBody
	public ListResult<RFilmListBean> getFilmList(@Validated GetFilmListParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RFilmListBean> res = new ListResult<RFilmListBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return roomController.getFilmList(param, request, response);
	}

	/**
	 * 锁定影厅（ 成功时msg返回有效截止时间）
	 **/
	@RequestMapping("/v1/roomLock")
	@ResponseBody
	public BaseResult roomLock(@Validated RoomLockParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return roomController.roomLock(param, request, response);
	}

	/**
	 * 解除影厅锁定
	 **/
	@RequestMapping("/v1/roomUnLock")
	@ResponseBody
	public BaseResult roomUnLock(@Validated RoomLockParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return roomController.roomUnLock(param, request, response);
	}

	/**
	 * 创建订单
	 **/
	@RequestMapping("/v1/createOrder")
	@ResponseBody
	public ObjectResult<ROrderInfoBean> createOrder(@Validated CreateOrderParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<ROrderInfoBean> res = new ObjectResult<ROrderInfoBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return roomController.createOrder(param, request, response);
	}

	/**
	 * 创建续时订单
	 **/
	@RequestMapping("/v1/createTimeOrder")
	@ResponseBody
	public ObjectResult<ROrderInfoBean> createTimeOrder(@Validated CreateTimeOrderParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<ROrderInfoBean> res = new ObjectResult<ROrderInfoBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return roomController.createTimeOrder(param, request, response);
	}

	/**
	 * 创建转厅订单
	 **/
	@RequestMapping("/v1/createChangeOrder")
	@ResponseBody
	public ObjectResult<ROrderInfoBean> createChangeOrder(@Validated CreateChangeOrderParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<ROrderInfoBean> res = new ObjectResult<ROrderInfoBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return roomController.createChangeOrder(param, request, response);
	}

	/**
	 * 订单设置授权价格(重复设置会重新计算，不累加)
	 **/
	@RequestMapping("/v1/setOrderAuthPrice")
	@ResponseBody
	public ObjectResult<ROrderInfoBean> setOrderAuthPrice(@Validated EditOrderAuthPriceParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<ROrderInfoBean> res = new ObjectResult<ROrderInfoBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return roomController.setOrderAuthPrice(param, request, response);
	}

	/**
	 * 支付方式
	 **/
	@RequestMapping("/v1/orderPayWay")
	@ResponseBody
	public ObjectResult<ROrderPayBean> orderPayWay(@Validated RoomOrderPayWayParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<ROrderPayBean> res = new ObjectResult<ROrderPayBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return roomController.orderPayWay(param, request, response);
	}

	/**
	 * 影厅开厅
	 **/
	@RequestMapping("/v1/roomOpen")
	@ResponseBody
	public BaseResult roomOpen(@Validated RoomOpenParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return roomController.roomOpen(param, request, response);
	}
}
